<template>
  <view class='box'>
  <view style="margin: 30rpx 20rpx; color: aliceblue;">
      RFID:
      <u-input v-model="RFID" :border="border" :focus="true" :height="100" placeholder=""
        :customStyle="{'color':'white'}" />
    </view>
    <view style="margin: 30rpx 20rpx; color: aliceblue;">
      名称:
      <u-input v-model="form.wuping_name" :border="border" :height="100" :disabled="true" placeholder=""
        :customStyle="{'color':'white'}" />
    </view>
    <view style="margin: 0 20rpx; color: aliceblue;">
      型号:
      <u-input v-model="form.xin_hao" :border="border" :height="100" :disabled="true" placeholder=""
        :customStyle="{'color':'white'}" />
    </view>
    <view style="margin: 30rpx 20rpx; color: aliceblue;">
      库室:
      <u-input v-model="form.hb_rock_ku_shi_name" :border="border" :height="100" :disabled="true" placeholder=""
        :customStyle="{'color':'white'}" />
    </view>
    <u-button style="margin: 0 20rpx;" @click="saveRfidData">保存</u-button>
    <u-button style="margin: 30rpx 20rpx;" @click="viewListRfid">查看列表</u-button>
    <u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
  const sdkwx = uni.requireNativePlugin('GGRfid-SdkWX');
  import sqlLite from '../../common/sqllite-utils.js';
  import { saveRfiddata } from './outPutInStorageManagement.js';
  export default {
    data() {
      return {
        RFID:'',
        form:{
          wuping_name:'',
          xin_hao:'',
          hb_rock_ku_shi_name:'',
          hb_rock_ku_shi_id:''
        },
        border:true
      }
    },
    onReady() {
      this.$refs.uToast.show({
        title: '开启扫描成功',
        type: 'success',
      });
      const readerName = '/dev/ttysWK0:115200';
      const packageSize = 64;
      const freeWait = 100;
      const power = 15;
      
      sdkwx.open(readerName, packageSize, freeWait, power);
      const that = this;
      // 设置回调事件
      sdkwx.setTagEpcCallback((res) => {
        that.RFID = res.log.epc;
        this.searchRfidInfo()
      });
    },
    onHide() {
      sdkwx.close();
    },
    methods: {
      saveRfidData() {
        saveRfiddata.call(this)
      },
      viewListRfid() {
        this.$u.route('/pages/rfidDataList/rfidDataList');
      },
      searchRfidInfo() {
        const tableName = 'Synchronoustables';
        sqlLite.selectFromTable(
                 	`select * from ${tableName} where rfid='${this.RFID}'`,
        ).then(res => {
          console.log(res,'ooooooooooooooooooo')
          this.form.id = res[0].id
          this.form.wuping_name = res[0].wuping_name
          this.form.xin_hao = res[0].xin_hao
          this.form.hb_rock_ku_shi_name = res[0].hb_rock_ku_shi_name
          this.form.hb_rock_ku_shi_id = res[0].hb_rock_ku_shi_id
          this.form.hb_rock_zhuangxh_id = res[0].hb_rock_zhuangxh_id
          console.log(this.form)
        })
      }
    }
  }
</script>

<style>
.box {
  color:'black'
}
</style>
